layui.use(['form','laypage','layer'],function(){
	
	var form = layui.form
	,layer = layui.layer
	,laypage = layui.laypage;
	
	$("#add-btn").on('click',function(){x_admin_show('新增','../task/toAdd',null,null,true)});
	  initPage();
	  
	  
	  function getData(pageIndex,pageSize){
	 	  var data = {};
	 	  data["pageIndex"] = pageIndex?pageIndex:1;
	 	  data["pageSize"] = pageSize?pageSize:10;
	 	  return data;
	   	}
	  
	  
	  function initPage(){
		  var data = getData();
		  ajaxPost("../task/list",data,
				  function(data){
			  createData(data.data.list);
			  laypage.render({
				  elem:'page',
				  count:data.data.total,
				  layout: ['count', 'prev', 'page', 'next', 'limit', 'skip']
			    ,jump: function(obj,first){
			    	if(!first){
			    		toPage(obj.curr,obj.limit);
			    	}
			    }
			  });
		  },
				  function(data){
					  layer.alert(data.errorMsg,{
							icon:5,
							title:"错误"
						});
				  });
	  }
	  
	  window.initPage = initPage;
	  function toPage(pageIndex,pageSize){
	 	  
	 	var data = getData(pageIndex,pageSize);
	 	  ajaxPost("../task/list",data,
	 			  function(data){createData(data.data.list);},
	 			  function(data){
	 				  layer.alert(data.errorMsg,{
	 						icon:5,
	 						title:"错误"
	 					});
	 			  });
	   }
	  
	  
	  function createData(data){
		  var content = [];
		  for(var i =0 ;i < data.length;i++){
			  var taskdata = data[i];
			  content.push('<tr>');
			  content.push('<td>'+taskdata.taskName+'</td>');
			  content.push('<td>'+taskdata.appName+'</td>');
			  content.push('<td>'+taskdata.planStartDateStr+'</td>');
			  content.push('<td>'+taskdata.planEndDateStr+'</td>');
			  content.push('<td>'+showStr(taskdata.runStartTime)+'</td>');
			  content.push('<td>'+(taskdata.testStatus == 1?"草稿":(taskdata.testStatus==2?"测试中":"已完成"))+'</td>');
			  
			  if(taskdata.testStatus == 1)
			  content.push(' <td class="td-manage"> '+
		                '<a title="编辑"  onclick="x_admin_show(\'编辑\',\'../task/toEdit?taskId='+taskdata.id+'\',null,null,true)" href="javascript:;">'+
		                  '<i class="layui-icon">&#xe642;</i>'+
		                '</a>'+
		            '</td>');
			  else
				 content.push(' <td class="td-manage"> '+
		                '<a title="查看"  style="margin-right:5px;" onclick="x_admin_show(\'查看\',\'../task/toView?taskId='+taskdata.id+'\',null,null,true)" href="javascript:;">'+
		                  '<i class="layui-icon">&#xe65f;</i>'+
		                '</a>'+
		                '<a title="查看进度"  onclick="x_admin_show(\'执行进度\',\'../caseRun/tolist?taskId='+taskdata.id+'\',null,null,true)" href="javascript:;">'+
		                  '<i class="layui-icon">&#xe6b2;</i>'+
		                '</a>'+
		            '</td>'); 
			  content.push('</tr>');
		  }
		  
		  $("#dg").empty().append(content.join(""));
	  }
	  
});